import { createRouter, createWebHistory } from 'vue-router'


const routes = [
  {
    path: '/',
    name: '',
    component: () => import("views/index/IndexView.vue"),
    meta: {
      title: '首页'
    }
  },

  {
    path: '/detail',
    name: 'detail',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ 'views/detail/DetailView.vue'),
    meta: {
      title: '商品详情'
    }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import("views/login/LoginView.vue"),
    meta: {
      title: '登录'
    }
  },
  {
    path: '/register',
    name: 'register',
    component: () => import("views/register/RegisterView.vue"),
    meta: {
      title: '注册'
    }
  },
  {
    path: '/shopcart',
    name: 'shopcart',
    component: () => import("views/shopcart/ShopcartView.vue"),
    meta: {
      title: '购物车'
    }
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from, next) => {
  //如果没哟登录，到login

    next();

  //设置标题
  document.title = to.meta.title;

 
})

export default router
